#include "lichenprotocol.h"
#include "lichenparsepacket.h"
#include "lichensendpacket.h"
#include "lichenfindpacket.h"

LiChenProtocol::LiChenProtocol(electronicscale::ElectronicScaleParam &param, QObject *parent)
    : LiChenProtocol(param, * new LiChenProtocolData(), parent)
{

}

LiChenProtocol::LiChenProtocol(electronicscale::ElectronicScaleParam &param, LiChenProtocolData &data, QObject *parent)
    : BaseProtocol (data, parent)
{
    m_param = &param;

    LiChenParsePacket *parser = new LiChenParsePacket(param, data, this);
    LiChenSendPacket *sender = new LiChenSendPacket(data, this);
    connect(sender, &BaseSendPacket::requestSend, this, &BaseProtocol::requestSend);

    connect(parser, &LiChenParsePacket::parseCompleted, this, &LiChenProtocol::parseCompleted);

    data.m_parser = parser;
    data.m_sender = sender;
}

LiChenProtocol::~LiChenProtocol()
{
    delete m_d->m_sender;
    delete m_d->m_parser;
}

LiChenSendPacket *LiChenProtocol::getSender()
{
    return static_cast<LiChenSendPacket*>(m_d->m_sender);
}
